#include "TestSphere.h"
#include "TextureManager.h"
#include <iostream>

#include <GL\glut.h>


//http://animationbegins.files.wordpress.com/2012/05/metal_texture_1_by_wojtar_stockfsfsf1.jpg

TestSphere::TestSphere() 
{

}

TestSphere::TestSphere(float radius, float mass, const std::string& texFilePath) : m_radius(radius)
{
	
	m_mass = mass;
	//m_pTexture = new Texture;
	//m_pTexture->Load(texFilePath);
	m_texPath = texFilePath;
	m_mat.SetIdentity();

	m_pos = Vec3f(0,15,0);

	CreateRigidBody(new btSphereShape(radius), mass);

	m_pRigidBody->setRestitution(1);
}

void TestSphere::Draw()
{

	Texture* tex = TheTextureManager::Instance()->GetTexture(m_texPath);
	glPushMatrix();

			btTransform btTrans;
			m_pMotionState->getWorldTransform(btTrans);
			btTrans.getOpenGLMatrix(m_mat.m_matrix);
			m_mat.MultiOpenGL();


			tex->EnableSphereMap();
			//m_pTexture->Draw();
			//TheTextureManager::Instance()->DrawTexture(m_texPath);
			tex->Draw();
			glutSolidSphere(m_radius, 16, 16);
			tex->DisableSphereMap();
			
	glPopMatrix();
}

void TestSphere::Update()
{
	btVector3 origin = m_pRigidBody->getWorldTransform().getOrigin();
	m_pos = Vec3f(origin.x(), origin.y(), origin.z());
	//btVector3 linVel = m_pRigidBody->getLinearVelocity();
	
	
}